#ifndef THINK_THINK_CONSOLE_INPUT_OPTION_H
#define THINK_THINK_CONSOLE_INPUT_OPTION_H

static char* think_console_input_option =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: yunwuxin <448901948@qq.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think\\console\\input;\n"
	"\n"
	"class Option\n"
	"{\n"
	"\n"
	"    const VALUE_NONE     = 1;\n"
	"    const VALUE_REQUIRED = 2;\n"
	"    const VALUE_OPTIONAL = 4;\n"
	"    const VALUE_IS_ARRAY = 8;\n"
	"\n"
	"    private $name;\n"
	"    private $shortcut;\n"
	"    private $mode;\n"
	"    private $default;\n"
	"    private $description;\n"
	"\n"
	"    /**\n"
	"     * 构造方法\n"
	"     * @param string       $name        选项名\n"
	"     * @param string|array $shortcut    短名称,多个用|隔开或者使用数组\n"
	"     * @param int          $mode        选项类型(可选类型为 self::VALUE_*)\n"
	"     * @param string       $description 描述\n"
	"     * @param mixed        $default     默认值 (类型为 self::VALUE_REQUIRED 或者 self::VALUE_NONE 的时候必须为null)\n"
	"     * @throws \\InvalidArgumentException\n"
	"     */\n"
	"    public function __construct($name, $shortcut = null, $mode = null, $description = \'\', $default = null)\n"
	"    {\n"
	"        if (0 === strpos($name, \'--\')) {\n"
	"            $name = substr($name, 2);\n"
	"        }\n"
	"\n"
	"        if (empty($name)) {\n"
	"            throw new \\InvalidArgumentException(\'An option name cannot be empty.\');\n"
	"        }\n"
	"\n"
	"        if (empty($shortcut)) {\n"
	"            $shortcut = null;\n"
	"        }\n"
	"\n"
	"        if (null !== $shortcut) {\n"
	"            if (is_array($shortcut)) {\n"
	"                $shortcut = implode(\'|\', $shortcut);\n"
	"            }\n"
	"            $shortcuts = preg_split(\'{(\\|)-?}\', ltrim($shortcut, \'-\'));\n"
	"            $shortcuts = array_filter($shortcuts);\n"
	"            $shortcut  = implode(\'|\', $shortcuts);\n"
	"\n"
	"            if (empty($shortcut)) {\n"
	"                throw new \\InvalidArgumentException(\'An option shortcut cannot be empty.\');\n"
	"            }\n"
	"        }\n"
	"\n"
	"        if (null === $mode) {\n"
	"            $mode = self::VALUE_NONE;\n"
	"        } elseif (!is_int($mode) || $mode > 15 || $mode < 1) {\n"
	"            throw new \\InvalidArgumentException(sprintf(\'Option mode \"%s\" is not valid.\', $mode));\n"
	"        }\n"
	"\n"
	"        $this->name        = $name;\n"
	"        $this->shortcut    = $shortcut;\n"
	"        $this->mode        = $mode;\n"
	"        $this->description = $description;\n"
	"\n"
	"        if ($this->isArray() && !$this->acceptValue()) {\n"
	"            throw new \\InvalidArgumentException(\'Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.\');\n"
	"        }\n"
	"\n"
	"        $this->setDefault($default);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取短名称\n"
	"     * @return string\n"
	"     */\n"
	"    public function getShortcut()\n"
	"    {\n"
	"        return $this->shortcut;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取选项名\n"
	"     * @return string\n"
	"     */\n"
	"    public function getName()\n"
	"    {\n"
	"        return $this->name;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 是否可以设置值\n"
	"     * @return bool 类型不是 self::VALUE_NONE 的时候返回true,其他均返回false\n"
	"     */\n"
	"    public function acceptValue()\n"
	"    {\n"
	"        return $this->isValueRequired() || $this->isValueOptional();\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 是否必须\n"
	"     * @return bool 类型是 self::VALUE_REQUIRED 的时候返回true,其他均返回false\n"
	"     */\n"
	"    public function isValueRequired()\n"
	"    {\n"
	"        return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 是否可选\n"
	"     * @return bool 类型是 self::VALUE_OPTIONAL 的时候返回true,其他均返回false\n"
	"     */\n"
	"    public function isValueOptional()\n"
	"    {\n"
	"        return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 选项值是否接受数组\n"
	"     * @return bool 类型是 self::VALUE_IS_ARRAY 的时候返回true,其他均返回false\n"
	"     */\n"
	"    public function isArray()\n"
	"    {\n"
	"        return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置默认值\n"
	"     * @param mixed $default 默认值\n"
	"     * @throws \\LogicException\n"
	"     */\n"
	"    public function setDefault($default = null)\n"
	"    {\n"
	"        if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {\n"
	"            throw new \\LogicException(\'Cannot set a default value when using InputOption::VALUE_NONE mode.\');\n"
	"        }\n"
	"\n"
	"        if ($this->isArray()) {\n"
	"            if (null === $default) {\n"
	"                $default = [];\n"
	"            } elseif (!is_array($default)) {\n"
	"                throw new \\LogicException(\'A default value for an array option must be an array.\');\n"
	"            }\n"
	"        }\n"
	"\n"
	"        $this->default = $this->acceptValue() ? $default : false;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取默认值\n"
	"     * @return mixed\n"
	"     */\n"
	"    public function getDefault()\n"
	"    {\n"
	"        return $this->default;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取描述文字\n"
	"     * @return string\n"
	"     */\n"
	"    public function getDescription()\n"
	"    {\n"
	"        return $this->description;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 检查所给选项是否是当前这个\n"
	"     * @param Option $option\n"
	"     * @return bool\n"
	"     */\n"
	"    public function equals(Option $option)\n"
	"    {\n"
	"        return $option->getName() === $this->getName()\n"
	"        && $option->getShortcut() === $this->getShortcut()\n"
	"        && $option->getDefault() === $this->getDefault()\n"
	"        && $option->isArray() === $this->isArray()\n"
	"        && $option->isValueRequired() === $this->isValueRequired()\n"
	"        && $option->isValueOptional() === $this->isValueOptional();\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif